/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <cmath>
using namespace std;
int DI(int origin,int target)
{
    int PI=0,weight=0;
    while (origin)
    {
        if (origin%10==target)
        {
            PI+=(int)target*pow(10,weight++);
        }
        origin/=10;
    }
    return PI;
}
int main_1016()
{
    int A,DA,B,DB;
    scanf("%d%d%d%d",&A,&DA,&B,&DB);
    printf("%d\n",DI(A,DA)+DI(B,DB));
	return 0;
}
